<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增加工异常')" />
    <!--<th:block th:include="include :: datetimepicker-css" />-->
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-abnormal-add">
            <input name="inventoryId" id="inventoryId" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">异常原膜编号：</label>
                <div class="col-sm-7">
                    <input id="number" class="form-control" type="text" required>
                </div>
                <a class="btn btn-warning btn-rounded btn-sm" onclick="checkNumber()"><i class="fa fa-refresh"></i>&nbsp;校验</a>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">厂家：</label>
                <div class="col-sm-8">
                    <input id="factory" class="form-control" disabled type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">材料名称：</label>
                <div class="col-sm-8">
                    <input id="materials" class="form-control" disabled type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">发现班次：</label>
                <div class="col-sm-8">
                    <input name="findNumber" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发现人：</label>
                <div class="col-sm-8">
                    <input name="discoverer" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">发现时间：</label>
                <div class="col-sm-8">
                    <input name="findDate" class="form-control time-input" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"
                           placeholder="yyyy-MM-dd HH:mm:ss" type="text">
                       <!--  <span class="input-group-addon"><i class="fa fa-calendar"></i></span> -->
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质量图片反馈：</label>
                <div class="col-sm-6">
                    <input id="imageUrl" name="file" multiple type="file" data-show-caption="true">
                </div>
                <div class="col-sm-1">
                    <a class="btn btn-success" onclick='sendFile("imageUrl")'><i class="fa fa-plus">图片上传</i></a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <div class="file-preview imageUrl" style="height: 100px">
                    </div>
                    <input name="imageUrl" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">质量视频反馈：</label>
                <div class="col-sm-6">
                    <input id="videoUrl" name="file" multiple type="file" data-show-caption="true">
                </div>
                <div class="col-sm-1">
                    <a class="btn btn-success" onclick='sendFile("videoUrl")'><i class="fa fa-plus">视频上传</i></a>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-8">
                    <div class="file-preview videoUrl" style="height: 100px">
                    </div>
                    <input name="videoUrl" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">异常原因：</label>
                <div class="col-sm-8">
                    <textarea name="reason" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!-- <th:block th:include="include :: datetimepicker-js" /> -->
    <script th:inline="javascript">
        var prefix = ctx + "process/abnormal"
        $("#form-abnormal-add").validate({
            focusCleanup: true
        });
        function submitHandler() {
            var number = $("#number").val();
            if(number == null || number == ''){
                layer.alert("请输入原膜编号");
                return;
            }
            if ($.validate.form()) {
                var data = $('#form-abnormal-add').serialize();
                data.inventoryId = $("#inventoryId").val();
                $.operate.save(prefix + "/add", data);
            }
        }
        function checkNumber(){
            var number = $("#number").val();
            if(number == null || number == ''){
                layer.alert("请输入原膜编号");
                return;
            }
            $.operate.post(prefix + "/checkNumber",{"number":number},function (result) {
                if(result.data!=null){
                    $("#factory").val(result.data.factoryName);
                    $("#materials").val(result.data.materialsName);
                    $("#inventoryId").val(result.data.id);
                }
            });
        }
        // $("input[name='findDate']").datetimepicker({
        //     format: "yyyy-mm-dd",
        //     minView: "month",
        //     autoclose: true
        // });
        // 上传文件
        function sendFile(name) {
            var val = $('#'+name)[0].files;
            var data = new FormData();
            data.append("file", val[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result!=null && result.code == web_status.SUCCESS) {
                        $('.'+name).html('<img src="'+result.url+'" style="height: 100%">');
                        $('[name="'+name+'"]').val(result.url);
                    } else {
                        $.modal.alertError("上传失败");
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败");
                }
            });
        }
    </script>
</body>
</html>